#include "../ourhdr.h"

int main(void)
{
    int n,fd[2];
    pid_t pid;
    char line[MAXLINE];

    if(pipe(fd) < 0)
    {
        err_sys("pipe error");
    }

    if((pid = fork()) < 0)
    {
        err_sys("fork error");
    }
    else if(pid>0) /*** parent ***/
    {
        close(fd[0]); //父进程中关闭读
        log_msg("parent pid->%d",getpid());
        write(fd[1], "hello world\n", 12);
    }
    else  /*** child ***/
    {
        close(fd[1]); //子进程中关闭写
        n=read(fd[0], line, MAXLINE);
        log_msg("child pid->%d",getpid());
        write(STDOUT_FILENO,line, n);
    }
    exit(0);
}
/***
 * 
zhaofeng@frankmac 14 % ./ipc01.cmd                         
parent pid->3962
child pid->3963
hello world
 * 
***/